# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=libsbml
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.18.0
pkgrel=1
pkgdesc="A file format for exchanging computational models in systems biology (mingw-w64)"
arch=('any')
license=("custom")
url="http://sbml.org/Software/libSBML/"
source=("http://sourceforge.net/projects/sbml/files/libsbml/${pkgver}/stable/libSBML-${pkgver}-core-plus-packages-src.tar.gz"
        01-cast-to-long.patch
        02-install-layout.patch)
sha256sums=('6c01be2306ec0c9656b59cb082eb7b90176c39506dd0f912b02e08298a553360'
            '2fa6e8d32818645cc42169d39d1e1d50764cc023ece438cdc1d4234e866e085d'
            'a53fa04481ec72348c5d23a12b395d9908cd4f996911dc046a6f926d1d34777d')
depends=("${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}-Source"
  patch -p1 -i ${srcdir}/01-cast-to-long.patch
  patch -p1 -i ${srcdir}/02-install-layout.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_SWIG=OFF \
    -DWITH_CPP_NAMESPACE=ON \
    -DLIBSBML_DEPENDENCY_DIR=${MINGW_PREFIX} \
    -DLIBXML_INCLUDE_DIR="${MINGW_PREFIX}/include/libxml2" \
    -DWITH_LIBXML=ON \
    -DWITH_EXPAT=OFF \
    -DWITH_BZIP2=ON \
    -DWITH_ZLIB=ON \
    -DWITH_PYTHON=ON \
    -DENABLE_LAYOUT=ON \
    -DENABLE_RENDER=ON \
    -DENABLE_QUAL=ON \
    -DENABLE_MULTI=ON \
    -DENABLE_COMP=ON \
    -DENABLE_FBC=ON \
    -DENABLE_GROUPS=ON \
    ../${_realname}-${pkgver}-Source

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
